def is_prime(n):
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

d = {
    "one": "1",
    "two": "2",
    "three": "3",
    "four": "4",
    "five": "5",
    "six": "6",
    "seven": "7",
    "eight": "8",
    "nine": "9",
    "zero": "0",
}

s = input()
lst = s.split()
if len(lst)!=3:
    print("Wrong input")
        exit()
    
num = ""
for word in lst:
    if word in d:
        num += d[word]
    else:
        print("Wrong input")
        exit()

num = int(num)

s = None
b = None

for n in range(num, num + 10000):
    if is_prime(n):
        b = n
        break

for n in range(num, 2, -1):
    if is_prime(n):
        s = n
        break

if b is None:
    print(s)
elif s is None:
    print(b)
elif b - num >= num - s:
    print(s)
else:
    print(b)

